<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <style>
color.lblue
{
    color:#1badcf ;
}

color.green
{
    color:#63f294 ;
}

input.text
{
    border-style:solid;
    border-color:#63f294 ;
    border-width: 3px;
    background-color:white;
    color:#2c137b ;
    font-weight: bold;
}


input.button
{
    color:#2c137b;
}
center
{
    alignment-adjust: central;
}
color.dblue
{
    color:#2c137b ;
}
        </style>
    </head>
    <body>
        
        <?php
$con = mysql_connect("localhost", "root", "root") or die('Could not connect: '.mysqli_error());
 // $con = mysqli_connect("localhost", "root", "");
  $selected = mysql_select_db("alignedvisions", $con) or die("Could not select alignedvisions");
  
  if (isset($_POST['submit'])) {
      $intern1=$_POST['intern1'];
      $intern2=$_POST['intern2'];
      $intern3=$_POST['intern3'];
      $consultant=$_POST['consultant'];
      $entrepreneur=$_POST['entrepreneur'];
      
      $cname=$_POST['nomeEmpresa'];
      //echo $intern1.$cname;
      $minhaQuery = mysql_query("UPDATE studentForm SET company = '$cname' WHERE login = '$intern1';");
      $res = mysql_query($minhaQuery);
      
      $minhaQuery = mysql_query("UPDATE studentForm SET company = '$cname' WHERE login = '$intern2';");
      $res = mysql_query($minhaQuery);
      
      $minhaQuery = mysql_query("UPDATE studentForm SET company = '$cname' WHERE login = '$intern3';");
      $res = mysql_query($minhaQuery);
      
      $minhaQuery = mysql_query("UPDATE consultantForm SET company = '$cname' WHERE login = '$consultant';");
      $res = mysql_query($minhaQuery);
      
      $minhaQuery = mysql_query("UPDATE entrepreneurForm SET company = '$cname' WHERE login = '$entrepreneur';");
      $res = mysql_query($minhaQuery);
      
      //falta ajustar o approved
      for($j=0; $j <50; $j++)
            {
                $userAproved=$_POST['approved'][$j];
                
                $classUser= mysql_query("select classification from login where username = '$userAproved';");
                $rows=mysql_fetch_array($classUser);
               
                if (strcmp($rows['classification'],"e") == 0){
                    
                    $sql="UPDATE entrepreneurForm SET week = week + 1 WHERE login = '$userAproved';";
                    mysql_query($sql);
                     $sql="UPDATE entrepreneurForm SET approved = 'yes' WHERE login = '$userAproved';";
                    mysql_query($sql);
                    
                }
                if (strcmp($rows['classification'],"i") == 0){
                    $sql="UPDATE studentForm SET week = week + 1 WHERE login = '$userAproved';";
                    mysql_query($sql);
                    $sql="UPDATE studentForm SET approved = 'yes' WHERE login = '$userAproved';";
                    mysql_query($sql);

                }
                if (strcmp($rows['classification'],"c") == 0){
                    $sql="UPDATE consultantForm SET week = week + 1 WHERE login = '$userAproved';";
                    mysql_query($sql);
                     $sql="UPDATE consultantForm SET approved = 'yes' WHERE login = '$userAproved';";
                    mysql_query($sql);

                }
                
                
          
            }
      
      echo 'DONE';
      
  }
  
  
  ?>
  
        
        <form name="form" action="admin.php" method="post">
            <center><t><color class='dblue' style="font-size:20pt;"><?php echo "Admin";?></color></t></center> <br><br>
            <div style='border:3px solid black; padding:10px;'>
                <color class="lblue">Company Name:  </color> <input class="text" type="text" name="nomeEmpresa" size="57" maxlength="57"/> <br><br>

                <color class="lblue">Intern 1:  </color> 
                <select name='intern1'>
                <option value="" style="display:none;"></option>
                <?php
                $minhaQuery = mysql_query("select * from studentForm where company is NULL;");
                while( $registrosDaTabela = mysql_fetch_assoc($minhaQuery) ) 
                {
                echo '<option value="'.$registrosDaTabela["login"].'" >'.$registrosDaTabela["lastName"].', '.$registrosDaTabela["firstName"].'</option>';
                } 
                ?>
                </select>

                <color class="lblue">Intern 2:  </color>
                <select name='intern2'>
                <option value="" style="display:none;"></option>
                <?php
                $minhaQuery = mysql_query("select * from studentForm where company is NULL;");
                while( $registrosDaTabela = mysql_fetch_assoc($minhaQuery) ) 
                {
                echo '<option value="'.$registrosDaTabela["login"].'" >'.$registrosDaTabela["lastName"].', '.$registrosDaTabela["firstName"].'</option>';
                } 
                ?>
                </select>

                <color class="lblue">Intern 3:  </color>
                <select name='intern3'>
                <option value="" style="display:none;"></option>
                <?php
                $minhaQuery = mysql_query("select * from studentForm where company is NULL;");
                while( $registrosDaTabela = mysql_fetch_assoc($minhaQuery) ) 
                {
                echo '<option value="'.$registrosDaTabela["login"].'" >'.$registrosDaTabela["lastName"].', '.$registrosDaTabela["firstName"].'</option>';
                } 
                ?>
                </select>
                <p>
                <color class="lblue">Consultant:  </color>
                <select name='consultant'>
                <option value="" style="display:none;"></option>
                <?php
                $minhaQuery = mysql_query("select * from consultantForm where company is NULL;");
                while( $registrosDaTabela = mysql_fetch_assoc($minhaQuery) ) 
                {
                echo '<option value="'.$registrosDaTabela["login"].'" >'.$registrosDaTabela["lastName"].', '.$registrosDaTabela["firstName"].'</option>';
                } 
                ?>
                </select>

                <color class="lblue">Entrepreneur:  </color>
                <select name='entrepreneur'>
                <option value="" style="display:none;"></option>
                <?php
                $minhaQuery = mysql_query("select * from entrepreneurForm where company is NULL;");
                while( $registrosDaTabela = mysql_fetch_assoc($minhaQuery) ) 
                {
                echo '<option value="'.$registrosDaTabela["login"].'" >'.$registrosDaTabela["lastName"].', '.$registrosDaTabela["firstName"].'</option>';
                } 
                ?>
                </select>
                
            </div>
            <br>
            <br>
            <br>
            <br>
            <center style='border:3px solid black;'><t><color class='dblue' ><?php echo "Waiting for Authorization <br> (select the checkbox to authorize)";?></color></t> <br><br>
            <?php
             
                    $i=0;
                    $getMsgs = "select * from studentForm WHERE approved='no';";
                    $resultmsgs = mysql_query($getMsgs);
                    while ($rowMsg = mysql_fetch_array($resultmsgs))
                    {
                        $value[$i] = $rowMsg['login'];
                        $week[$i] = $rowMsg['week'];
                        $lName[$i] =  $rowMsg['lastName'];
                        $fName[$i]=  $rowMsg['firstName'];
                        $i ++;

                    }
                    for($j=0; $j <$i; $j++)
                    {
                        echo '<color class="green">';
                        echo    "<a href='initialPage.php?user=$value[$j]&week=week$week[$j]&classification=i'>";
                        echo  '<input type="checkbox" name="approved['.$j.']" value='.$value[$j].'>'.$lName[$j].', '.$fName[$j].' ('.$week[$j].')-intern-'.'</p> </green>';
                       // echo  '<input type="checkbox" name="approved[]" value='.$value[$j].';">'.$lName[$j].', '.$fName[$j].' ('.$week[$j].')'.'</p> </green>';
                        echo "  </a> ";
                    }
                    
                    $getMsgs = "select * from entrepreneurForm WHERE approved='no';";
                    $resultmsgs = mysql_query($getMsgs);
                    while ($rowMsg = mysql_fetch_array($resultmsgs))
                    {
                        $value[$i] = $rowMsg['login'];
                        $week[$i] = $rowMsg['week'];
                        $lName[$i] =  $rowMsg['lastName'];
                        $fName[$i]=  $rowMsg['firstName'];
                        $i ++;
                    }
                    for(; $j <$i; $j++)
                    {
                        echo '<color class="green">';
                        echo    "<a href='initialPage.php?user=$value[$j]&week=week$week[$j]&classification=e'>";
                        echo  '<input type="checkbox" name="approved['.$j.']" value='.$value[$j].'>'.$lName[$j].', '.$fName[$j].' ('.$week[$j].')-entrepreneur-'.'</p> </green>';
                       // echo  '<input type="checkbox" name="approved[]" value='.$value[$j].';">'.$lName[$j].', '.$fName[$j].' ('.$week[$j].')'.'</p> </green>';
                        echo "  </a> ";
                    }
                    
                    
                      mysqli_close($con);
            ?>
                  </center>
            <center> <input class="button" name="submit" type="submit" value="Save and apply this change"/> </center>
        </form>
        
        
        
        
    </body>
</html>
